Grokking Database Fundamentals for Tech Interviews
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction to Database Systems
Course Overview
Overview of Databases
Core Components of Database
Database Architectures
Relational Vs. Non-relational Databases
Data Storage in DBMS
Data Storage Fundamentals
File Organization in DBMS
Data Compression and Encoding
Quiz
Indexing in DBMS
Introduction to Database Indexes
Single Level Indexing
Tree-Based Indexing Techniques
Hash-Based Indexing
Bloom Filters
Quiz
Transaction Management
Understanding the Transaction
Atomicity
Consistency
Isolation
Durability
Quiz
Understanding the Concurrency Control
Optimistic vs. Pessimistic Concurrency Control
Lock-Based Concurrency Control
Timestamp-Based Concurrency Control
Multiversion Concurrency Control (MVCC)
Quiz
Fundamentals of Distributed Databases
Partitioning in Databases
Partitioning Types
Sharding in Databases
Distributed Query Processing
Quiz
Replication in Databases
Replication Topologies
Understanding the Consistency Models in Databases
The CAP Theorem and Its Implications
Quiz
Understanding the Consensus
Consensus algorithms
Leader Election Strategies
Quiz
Understanding the Fault Tolerance
Logging Mechanisms in Databases
Checkpointing and Recovery Basics
Coordinated Recovery in Distributed Systems
High Availability Through Replication and Failover
Ensuring Data Resilience: Redundancy, Mirroring, and Recovery
Quiz
Introduction to NoSQL
Key-Value Stores
Document-Oriented Databases
Column-Family and Wide-Column Stores
Graph Databases
Quiz
Quora System Design & Database Design
TikTok System Design & Database Design
Airbnb System Design & Database Design
Snapchat System Design & Database Design
Durability

What is Durability?

Durability, one of the ACID properties, ensures that once a transaction is successfully committed, its changes are permanently stored in the database. Even in the event of system crashes, power failures, or hardware malfunctions, the database guarantees that committed data is not lost.

Once saved, your data is safe and will not be lost after failures.

Image

Importance of Durability

  1. Data Reliability:

    • Applications depend on durability to ensure that important information is not lost after a transaction is completed.
    • Example: A bank transaction deducting $100 from an account must remain recorded even if the system crashes immediately afterward.
  2. Fault Tolerance:

    • Durability ensures that a database can recover to a consistent state after failures, with all committed transactions intact.
  3. User Trust:

    • Durability builds user trust by providing confidence that their data is safe and persistent.

How Durability is Achieved

Modern databases use a combination of techniques to ensure durability:

1. Write-Ahead Logging (WAL)

  • Before applying changes to the database, a log of the changes is written to a persistent storage medium (like a disk).
  • In case of a failure, the log is replayed to recover the committed transactions.

Example:

  • Transaction T1 commits, and its changes are logged.
  • System crashes before changes are written to the database.
  • On recovery, the log is replayed to reapply T1's changes, ensuring durability.

2. Checkpointing

  • Periodically, the database takes a "snapshot" of its current state and saves it to disk.
  • Checkpoints reduce recovery time by limiting the number of logs that need to be replayed during recovery.

3. Synchronous Disk Writes

  • Changes are written to disk immediately upon committing a transaction.
  • Ensures that the database doesn't rely on volatile memory (e.g., RAM) to store committed data.

4. Replication

  • Changes are replicated to multiple nodes or servers to ensure data redundancy.
  • Even if one node fails, other nodes maintain a consistent copy of the data.

Example:

  • A distributed database like MongoDB replicates changes across its replica set.
  • A failure in the primary node doesn’t affect data availability because replicas retain the committed data.

Examples of Durability in Action

Scenario 1: Bank Transaction

  1. User transfers $1,000 from Account A to Account B.
  2. Transaction commits, and the changes are written to the transaction log.
  3. A power failure occurs immediately after the commit.
  4. On recovery, the database uses the log to ensure that the $1,000 transfer is preserved.

Scenario 2: E-commerce Order

  1. A user places an order for a product.
  2. The transaction commits, and the database saves the order details and payment information.
  3. A system crash occurs right after the commit.
  4. The user’s order is still recorded because the database ensures durability.
Isolation
Quiz
Mark as Completed

On this page

What is Durability?

Importance of Durability

How Durability is Achieved

  1. Write-Ahead Logging (WAL)
  1. Checkpointing
  1. Synchronous Disk Writes
  1. Replication

Examples of Durability in Action

Scenario 1: Bank Transaction

Scenario 2: E-commerce Order